package test;

import org.apache.commons.pool2.ObjectPool;

public class StringProcessThread extends Thread {
	
	private ObjectPool<StringFormat> pool;
	private String text;

	public StringProcessThread(ObjectPool<StringFormat> pool, String text) {
		this.pool = pool;
		this.text = text;
	}

	public void run() {
		StringFormat stringFormat = null;
		try {
			stringFormat = pool.borrowObject();
			String formattedStr = stringFormat.format(text);
			System.out.println(formattedStr);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (stringFormat != null) {
					pool.returnObject(stringFormat);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
